#include "includes_fw.h"
#include "config_fw.h"
#include "hdm_ctl.h"
#include "lib_retina.h"
#include "flash_ctl.h"

#if SUPPORT_FLASH_LIGHT

#if BIND_FLASH_LM3554

void FLASH_LM3554_TorchModeOn(MMP_UBYTE level);
void FLASH_LM3554_TorchModeOff(void);

void FLASH_LM3554_Init(void)
{
	//MMP_USHORT read_value;

    //VR_FLASH_ConfigI2C(0x53, ISP_I2C_TYPE_1A1D);
    //MMPF_OS_Sleep(1);

    MMPF_FLASH_WriteI2C(0xB0, 0x08);  // Flash Brightness

#if 0
    MMPF_FLASH_ReadI2C(0xA0, &read_value);  //  should be 0x50.
    RTNA_DBG_Str(3, " Read LM3554 Reg[0xA0] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    MMPF_FLASH_ReadI2C(0xB0, &read_value);  //  should be 0x68.
    RTNA_DBG_Str(3, " Read LM3554 Reg[0xB0] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    MMPF_FLASH_ReadI2C(0xC0, &read_value);  //  should be 0x4F.
    RTNA_DBG_Str(3, " Read LM3554 Reg[0xC0] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    MMPF_FLASH_ReadI2C(0xD0, &read_value);  //  should be 0x40.
    RTNA_DBG_Str(3, " Read LM3554 Reg[0xD0] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    MMPF_FLASH_ReadI2C(0xE0, &read_value);  //  should be 0x42.
    RTNA_DBG_Str(3, " Read LM3554 Reg[0xE0] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    MMPF_FLASH_ReadI2C(0xF0, &read_value);  //  should be 0xF0.
    RTNA_DBG_Str(3, " Read LM3554 Reg[0xF0] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    MMPF_FLASH_ReadI2C(0x20, &read_value);  //  should be 0x80.
    RTNA_DBG_Str(3, " Read LM3554 Reg[0x20] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    MMPF_FLASH_ReadI2C(0x80, &read_value);  //  should be 0xF0.
    RTNA_DBG_Str(3, " Read LM3554 Reg[0x80] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
#endif

/*    
    FLASH_LM3554_TorchModeOn(1);
    MMPF_FLASH_ReadI2C(0xA0, &read_value);  //  should be 0x50.
    RTNA_DBG_Str(3, " Read LM3554 Reg[0xA0] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    MMPF_OS_Sleep(200);
    FLASH_LM3554_TorchModeOff();
    MMPF_FLASH_ReadI2C(0xA0, &read_value);  //  should be 0x50.
    RTNA_DBG_Str(3, " Read LM3554 Reg[0xA0] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
*/    

}

void FLASH_LM3554_FlashModeOn(MMP_UBYTE level)
{
    RTNA_DBG_Str(3, "FLASH_LM3554_FlashModeOn().....\r\n");  
    MMPF_FLASH_WriteI2C(0xB0, 0x0B);  // [7:6]: 10->Device operates in torch and flash modes, [3]: Start flash/Timer
}

void FLASH_LM3554_FlashModeOff(void)
{
    RTNA_DBG_Str(3, "FLASH_LM3554_FlashModeOff().....\r\n");  
    MMPF_FLASH_WriteI2C(0xB0, 0x08);  // [7:6]: 
}

void FLASH_LM3554_TorchModeOn(MMP_UBYTE level)
{
    RTNA_DBG_Str(3, "FLASH_LM3554_TorchModeOn().....\r\n");  
    MMPF_FLASH_WriteI2C(0xA0, 0x52);  // [7:6]: 10->Device operates in torch and flash modes, [3]: Start flash/Timer
}

void FLASH_LM3554_TorchModeOff(void)
{
    RTNA_DBG_Str(3, "FLASH_LM3554_TorchModeOff().....\r\n");  
    MMPF_FLASH_WriteI2C(0xA0, 0x50);  // [7:6]: 10->Device operates in torch and flash modes, [3]: Start flash/Timer
}

#endif

#endif
